import com.hncg.util.DBUtil;
import lombok.experimental.StandardException;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MyTest01 {
    @Test
    public  void testConn() throws SQLException {
        //获得连接
        Connection conn = DBUtil.getConnection();
        //编写sql语句
        String sql = "select * from t_user";
        //预编译sql语句
        PreparedStatement pstmt = conn.prepareStatement(sql);
        //执行查询并返回结果集
        ResultSet rs = pstmt.executeQuery();
        //循环遍历结果集中的数据
        while(rs.next()){
            System.out.println(rs.getInt("id")+","+rs.getString("name")+","+
                    rs.getInt("age")+","+rs.getString("hiredate"));
        }
    }

}
